package com.woniuxy.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.entity.RbacPerm;
import com.woniuxy.entity.dto.PermInfo;
import com.woniuxy.mapper.RbacPermMapper;
import com.woniuxy.service.RbacPermService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 权限表 服务实现类
 * </p>
 *
 * @author linKe
 * @since 2021-11-25
 */
@Service
public class RbacPermServiceImpl extends ServiceImpl<RbacPermMapper, RbacPerm> implements RbacPermService {
    @Resource
    private RbacPermMapper rbacPermMapper;

    @Override
    public List<RbacPerm> findByRoleId(int roleId) {
        return rbacPermMapper.findByRoleId(roleId);
    }

    @Override
    public List<PermInfo> findPermInfoByRoleId(Integer id) {
        return rbacPermMapper.findPermInfoByRoleId(id);
    }



    @Override
    public List<RbacPerm> findAllPage(int currentPage, int size) {
        Page<RbacPerm> page = new Page<>(currentPage,size);
        return rbacPermMapper.selectPage(page, null).getRecords();
    }

    @Override
    public RbacPerm findOneById(int id) {
        return rbacPermMapper.selectById(id);
    }

    @Override
    public int addPerm(RbacPerm rbacPerm) {
        return rbacPermMapper.insert(rbacPerm);
    }

    @Override
    public int updatePerm(RbacPerm rbacPerm) {
        return rbacPermMapper.updateById(rbacPerm);
    }

    @Override
    public int deletePerm(int id) {
        return rbacPermMapper.deleteById(id);
    }

    @Override
    public List<RbacPerm> findAllPerm() {
        return rbacPermMapper.selectList(null);
    }
}
